/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.jitclouds.mda;

import br.ufba.lasid.comm.Host;
import br.ufba.lasid.ds.fd.FailureDetector;
import br.ufba.lasid.jitclouds.mda.api.JiTFailureDetectorAPI;
import java.util.ArrayList;
import java.util.List;


/**
 *
 * @author aliriosa
 */
public class JiTFailureDetector extends FailureDetector implements JiTFailureDetectorAPI{

    @Override
    public String getName() throws Exception {
        return "JiTFailureDetector";
    }       
    
    
    @Override
    public void deploy() throws Exception{
        
        List hosts = JiTContext.getConfiguration().getList("JiTFailureDetector.hosts", new ArrayList());
     
        for(Object host : hosts){            
            
            String haddr = (String) host;
            
            this.register(haddr, Host.isLocalAddress(haddr));            
            
        }
        
        long period = JiTContext.getConfiguration().getLong("JiTFailureDetector.period" , 1000L);
        long timeout= JiTContext.getConfiguration().getLong("JiTFailureDetector.timeout", 100L);
        
        this.buildup();
        
        this.setPeriod(period);
        this.setTimeout(timeout);
        
        this.startup();
    }        
    
    public static void main(String[] args) throws Exception{
        JiTFailureDetector fd = new JiTFailureDetector();
        fd.deploy();
    }
}
